package com.dc.entity;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 *  8- 清洁/冲水  超水除锈  单船工序
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "t_workflow_water_clean")
public class WorkflowWaterCleanEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "submit_time")
    @JsonFormat(pattern = "yyyy-MM-dd")
    // 生成
    private Date submitTime = new Date();        // 填写日期

    @Transient
    private Long shipRepairId;      // 维修记录 外键id

    @Transient
    private String shipName;        // 船体名称

    @Transient
    private String reporter;        // 填报人

    @Column(name = "room", length = 50)     // 车间
    private String room;

    ////////////////////////////////////////////

    @Column(name = "type", length = 10)
    private String type;            // 工序名称:   清洁/冲水    超水除锈

    @Column(name = "area")
    private Double area;            // 施工面积(m²)

    @Column(name = "place", length = 50)
    private String place;           // 施工位置

    @Transient
    private Double powers;          // 子表的和

    ////////////////////////////////////////////

    @JsonIgnoreProperties(value = { "workflowWaterCleanEntity" })
    @OneToMany(cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH}, fetch = FetchType.EAGER)
    @JoinColumn(name = "workflow_water_clean_id", referencedColumnName = "id")
    private List<WorkflowWaterCleanChildEntity> inner = new ArrayList<>();

    @JsonIgnore
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "ship_repair_id", columnDefinition = "bigint unsigned NOT NULL")
    private ShipRepairEntity shipRepairEntity;

    @Override
    public String toString() {
        return "WorkflowWaterCleanEntity{" +
                "id=" + id +
                ", submitTime=" + submitTime +
                ", shipRepairId=" + shipRepairId +
                ", shipName='" + shipName + '\'' +
                ", reporter='" + reporter + '\'' +
                ", type='" + type + '\'' +
                ", area=" + area +
                ", place=" + place +
                ", powers=" + powers +
                '}';
    }
}
